package com.huiyujinrong.qiangdanbao.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.huiyujinrong.qiangdanbao.R;
import com.huiyujinrong.qiangdanbao.bean.MessageBean;
import com.huiyujinrong.qiangdanbao.utils.DataUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MessageAdapter extends BaseAdapter {

    private Context context;
    private List<MessageBean.list> list;

    public MessageAdapter(Context context, List<MessageBean.list> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_message, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.m_title.setText(list.get(position).getMsg_title());

        holder.m_time.setText(DataUtils.getDate(list.get(position).getCreate_time()));

        holder.m_content.setText(list.get(position).getMsg_content());

        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.m_title)
        TextView m_title; //标题
        @BindView(R.id.m_content)
        TextView m_content; //内容
        @BindView(R.id.m_time)
        TextView m_time; //时间

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
